package tech.ezrealc.fall2023.repository;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tech.ezrealc.fall2023.model.user.UserDO;
import tech.ezrealc.fall2023.model.user.UserDTO;

import java.util.List;

@Repository
public interface UserRepository {
    public static final Integer ROLE_STUDENT = 1;

    @Select("select id, name, email, role from system_user where email = #{email} and password = #{password}")
    UserDTO authenticate(@Param("email") String email, @Param("password") String password);

    @Select("select id, name, email, role from system_user join system_session on system_user.id = system_session.user where system_session.token = #{token}")
    UserDTO findByToken(@Param("token") String token);

    @Select("select id, name from system_user where role = #{role}")
    List<UserDO> selectByRole(@Param("role") Integer role);

}
